local path "C:\Users\pgi1\Dropbox\Coal 2021 _ Joe Peter\Bank Regressions\"
cd "`path'\data"
set seed 100
set more off
clear



use  loan_year_vars_dataset, clear

//edit if lender=="BofA Securities"

bysort ultimateparentid year: keep if _n==1
xtset ultimateparentid year

keep if year>=2000 & year<=2020

est clear


//  Test for effect of relationship

est clear


xtreg loans_mtr_ln treated  log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln y_* , fe vce(cluster ultimateparentid)
est store e1
estadd local fes "Bank and Year"

xtreg loans_mtr_rel_ln treated  log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln y_* , fe vce(cluster ultimateparentid)
est store e2
estadd local fes "Bank and Year"

xtreg loans_mtr_norel_ln treated  log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln y_* , fe vce(cluster ultimateparentid)
est store e3
estadd local fes "Bank and Year"


esttab e1 e2 e3 using "`path'\tables\table-5.rtf",  replace compress nogaps se onecell b(3) modelwidth(6) ///
title("Table 5: Number of Loans to Relationship and Non-Relationship Borrowers") mtitles( "Any"  "Relationship" "No Relationship" ) ///
stats(fes r2_a  N , fmt(%9.0fc %9.3fc %9.0fc ) labels("Fixed Effects" "Adj. R-squared" "Observations" ) ) ///
label collabels(none)  starlevels(* 0.10 ** 0.05 *** 0.01) nonote ///
order(treated log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln) keep(treated log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln)



exit

/